package com.kuanter.kuanterauto.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Handler;

import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.constants.HttpConfigAPI;
import com.kuanter.kuanterauto.constants.MainConstants;
import com.kuanter.kuanterauto.entity.CarInsurance;
import com.kuanter.kuanterauto.entity.City;
import com.kuanter.kuanterauto.entity.CityArea;
import com.kuanter.kuanterauto.entity.CityArea.Circle;
import com.kuanter.kuanterauto.entity.DJDTO;
import com.kuanter.kuanterauto.entity.KuanterService;
import com.kuanter.kuanterauto.entity.KuanterService.Service;
import com.kuanter.kuanterauto.entity.MerchanDetailService;
import com.kuanter.kuanterauto.entity.MerchanInfo;
import com.kuanter.kuanterauto.entity.MerchanServiceInfo;
import com.kuanter.kuanterauto.entity.NSDTO;
import com.kuanter.kuanterauto.entity.Restrictions;
import com.kuanter.kuanterauto.entity.SiteInfo;
import com.kuanter.kuanterauto.entity.THDTO;
import com.kuanter.kuanterauto.entity.WearherInfo;

public class JsonParser {

	//获取网点信息
	public static Map getSites(String json) {
		Map map = new HashMap();
		if(json == null) return map;
		List<SiteInfo> sites = null;
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				int sum = object.optInt("maxResult");
				map.put("sum", sum);
				
				JSONArray array = object.optJSONArray("shopInfoList");
				if(array != null && array.length() > 0) {
					sites = new ArrayList<SiteInfo>();
					for(int i = 0; i < array.length(); i++) {
						SiteInfo info = new SiteInfo();
						JSONObject jo = array.optJSONObject(i);
						info.setId(jo.optInt("id"));
						info.setSiteDistance(jo.optString("distance"));
						info.setSiteName(jo.optString("shopName"));
						Double longtitude = jo.optDouble("shopLon");
						Double latitude = jo.optDouble("shopIat");
						GeoPoint point = new GeoPoint((int)(latitude * 1E6), (int)(longtitude * 1E6));
						info.setPoint(point);
						info.setScore(jo.optString("score"));
						info.setMinServicePrice(jo.optString("minServicePrice"));
						info.setMaxServicePrice(jo.optString("maxServicePrice"));
						sites.add(info);
					}
					map.put("siteList", sites);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		
		return map;
	}
	
	//获取商户的信息以及服务信息
	public static List<KuanterService> getKuanterService(String json) {
		List<KuanterService> list_all = new ArrayList<KuanterService>();
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONArray array = object.optJSONArray("serviceCategoryList");
				if(array != null && array.length() > 0) {
					for(int i = 0; i < array.length(); i++) {
						KuanterService kuanterService = new KuanterService();
						JSONObject kuanterJson = array.optJSONObject(i);
						kuanterService.setServiceID(kuanterJson.optString("id"));
						kuanterService.setServiceType(kuanterJson.optString("categoryName"));
						kuanterService.setSeq(kuanterJson.optString("seq"));
						kuanterService.setParentId(kuanterJson.optString("parentId"));
						
						JSONArray array_service = kuanterJson.optJSONArray("subCategory");
						if(array_service != null && array_service.length() > 0) {
							List<Service> list_service = new ArrayList<KuanterService.Service>();
							for(int j = 0; j < array_service.length(); j++) {
								JSONObject service_json = array_service.optJSONObject(j);
								Service service = new Service();
								service.setServiceID(service_json.optString("id"));
								service.setServiceName(service_json.optString("categoryName"));
								service.setSeq(service_json.optString("seq"));
								service.setParentId(service_json.optString("parentId"));
								service.setSubCategory(service_json.optString("subCategory"));
								list_service.add(service);
							}
							kuanterService.setList_service(list_service);
						}
						
						/*KuanterService kkk = new KuanterService();
						kkk.setServiceType("特惠");
						kkk.setServiceID(MainConstants.TH);
						list_all.add(kkk);*/
						
						if(!kuanterService.getServiceID().equals(MainConstants.QT)) {
							list_all.add(kuanterService);
						}
//						list_all.add(kuanterService);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return list_all;
	}
	
	//获取城市列表
	public static List<City> getCitys(String json) {
		List<City> citys = null;
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONArray array = object.optJSONArray("cityList");
				if(array != null && array.length() > 0) {
					citys = new ArrayList<City>();
					for(int i = 0; i < array.length(); i++) {
						City city = new City();
						JSONObject js = array.optJSONObject(i);
						city.setCityID(js.optString("areaCode"));
						city.setCityName(js.optString("areaName"));
						city.setGpsCoordinate(js.optString("gpsCoordinate"));
						city.setStandardCoordinate(js.optString("standardCoordinate"));
						city.setAreaIdForWeather(js.optString("areaIdForWeather"));
						citys.add(city);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return citys;
	}
	
	public static MerchanInfo getMerchanInfo(String json,List<KuanterService> services,String currentTypeID) {
		MerchanInfo merchanInfo = null;
		Map<String, List<MerchanDetailService>> map = new HashMap<String, List<MerchanDetailService>>();
		List<MerchanServiceInfo> others = new ArrayList<MerchanServiceInfo>();
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				merchanInfo = new MerchanInfo();
				JSONObject shop = object.optJSONObject("shop");
				merchanInfo.setQueueingProbability(shop.optString("queueingProbability"));
				merchanInfo.setMerchanAddress(shop.optString("shopAddress"));
				merchanInfo.setMerchanImgUrl(MainConstants.HOST_test + shop.optString("picAddr"));
				merchanInfo.setMerchanPhone(shop.optString("shopPhone"));
				
				JSONArray serlist = shop.optJSONArray("serviceList");
				if(serlist != null && serlist.length() > 0) {
					for(int i = 0; i < serlist.length(); i++) {
						JSONObject jo = serlist.optJSONObject(i);
						MerchanDetailService detail = new MerchanDetailService();
						detail.setCategoryId(jo.optString("categoryId"));
						detail.setDetailIntegral(jo.optDouble("facePrice"));
						detail.setDetailName(jo.optString("serviceName"));
						detail.setDetailPrice(jo.optDouble("cashPrice"));
						detail.setId(jo.optString("id"));
						if(map.containsKey(detail.getCategoryId())) {
							map.get(detail.getCategoryId()).add(detail);
						} else {
							List<MerchanDetailService> list_detail = new ArrayList<MerchanDetailService>();
							list_detail.add(detail);
							map.put(detail.getCategoryId(), list_detail);
						}
					}
				}
				
				Set<String> sid = map.keySet();
				Iterator<String> is = sid.iterator();
				while(is.hasNext()) {
					String cid = is.next();
					for(KuanterService ks : services) {
						List<Service> ls = ks.getList_service();
						for(int i = 0; i < ls.size(); i++) {
							if(ls.get(i).getServiceID().equals(cid)) {
								MerchanServiceInfo msi = new MerchanServiceInfo();
								msi.setId(ls.get(i).getServiceID());
								msi.setServiceName(ls.get(i).getServiceName());
								msi.setDetails(map.get(cid));
								if(cid.equals(currentTypeID)) {
									merchanInfo.setCurrentService(msi);
								} else {
									others.add(msi);
								}
							}
						}
					}
				}
				merchanInfo.setList_other_service(others);
				
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return merchanInfo;
	}
	
	public static List<CityArea> getArea(String json,Handler handler) {
		List<CityArea> list_area = new ArrayList<CityArea>();
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONArray ja_area = object.optJSONArray("areaList");
				if(ja_area != null && ja_area.length() > 0) {
					for(int i = 0; i < ja_area.length(); i++) {
						CityArea area = new CityArea();
						JSONObject jo = ja_area.optJSONObject(i);
						area.setAreaID(jo.optString("areaCode"));
						area.setCityarea(jo.optString("areaName"));
						area.setGpsCoordinate(jo.optString("gpsCoordinate"));
						area.setStandardCoordinate(jo.optString("standardCoordinate"));
						list_area.add(area);
					}
				}
				if(list_area != null) {
					for(int i = 0; i < list_area.size(); i++) {
						CityArea area = list_area.get(i);
						new Thread(new GetAreaInfo(area.getAreaID(), handler, area)).start();
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return list_area;
	}
	
	
	static class GetAreaInfo implements Runnable {
		String supAreaCode;
		Handler handler;
		CityArea ca;
		public GetAreaInfo(String supAreaCode,Handler handler,CityArea ca) {
			this.supAreaCode = supAreaCode;
			this.handler = handler;
			this.ca = ca;
		}

		@Override
		public void run() {
			List<NameValuePair> params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("supAreaCode",supAreaCode));
			
			HttpClient client = new DefaultHttpClient();
			HttpPost post = new HttpPost(MainConstants.HOST_test + HttpConfigAPI.FINDAREA);
			HttpResponse respons = null;
			String result = "";
			try {
				if (params != null) {
					UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
							params, HTTP.UTF_8);
					post.setEntity(entity);
				}

				client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);	//连接超时
				client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);   //读取超时
				respons = client.execute(post);

				if (respons.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
					result = EntityUtils.toString(respons.getEntity());
					List<Circle> list_cilcle = null;
					JSONObject object = new JSONObject(result);
					if(StringUtils.isSuccess(result)) {
						list_cilcle = new ArrayList<Circle>();
						Circle all = new Circle();
						all.setCircleID(ca.getAreaID());
						all.setCircleName(ca.getCityarea() + "全境");
						all.setGpsCoordinate(ca.getGpsCoordinate());
						all.setStandardCoordinate(ca.getStandardCoordinate());
						list_cilcle.add(all);
						JSONArray ja_area = object.optJSONArray("areaList");
						if(ja_area != null && ja_area.length() > 0) {
							for(int i = 0; i < ja_area.length(); i++) {
								Circle circle = new Circle();
								JSONObject jo = ja_area.optJSONObject(i);
								circle.setCircleID(jo.optString("areaCode"));
								circle.setCircleName(jo.optString("areaName"));
								circle.setGpsCoordinate(jo.optString("gpsCoordinate"));
								circle.setStandardCoordinate(jo.optString("standardCoordinate"));
								list_cilcle.add(circle);
							}
						}
						ca.setCircleList(list_cilcle);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			} 
		}
		
	}
	
	public static List<CarInsurance> getFinancial(String json) {
		List<CarInsurance> list_financial = new ArrayList<CarInsurance>();;
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONArray ja_finan = object.optJSONArray("bankList");
				if(ja_finan != null && ja_finan.length() > 0) {
					for(int i = 0; i < ja_finan.length(); i++) {
						CarInsurance ci = new CarInsurance();
						JSONObject jo = ja_finan.optJSONObject(i);
						ci.setInsuranceID(jo.optString("id"));
						ci.setInsuranceImgUrl(jo.optString("logoURL"));
						ci.setInsuranceAd(jo.optString("campaignInfo"));
						ci.setPhoneName1(jo.optString("phoneName1"));
						ci.setInsuranceTel(jo.optString("phoneNumber1"));
						
						ci.setPhoneName2(jo.optString("phoneName2"));
						ci.setRenewalTel(jo.optString("phoneNumber2"));
						
						ci.setPhoneName3(jo.optString("phoneName3"));
						ci.setPhonenum3(jo.optString("phoneNumber3"));
						
						ci.setPhoneName4(jo.optString("phoneName4"));
						ci.setPhonenum4(jo.optString("phoneNumber4"));
						
						ci.setInsuranceName(jo.optString("hqname"));
						
						if(ci.getPhoneName1().equals("客服电话")) {
							if(ci.getInsuranceTel() != null && !ci.getInsuranceTel().equals("") && !ci.getInsuranceTel().equals("null")) {
								ci.setLcdh(ci.getInsuranceTel());
							} else {
								ci.setLcdh("暂无");
							}
						} else if(ci.getPhoneName2().equals("客服电话")) {
							if(ci.getRenewalTel() != null && !ci.getRenewalTel().equals("") && !ci.getRenewalTel().equals("null")) {
								ci.setLcdh(ci.getRenewalTel());
							} else {
								ci.setLcdh("暂无");
							}
						} else if(ci.getPhoneName3().equals("客服电话")) {
							if(ci.getPhonenum3() != null && !ci.getPhonenum3().equals("") && !ci.getPhonenum3().equals("null")) {
								ci.setLcdh(ci.getPhonenum3());
							} else {
								ci.setLcdh("暂无");
							}
						} else if(ci.getPhoneName4().equals("客服电话")) {
							if(ci.getPhonenum4() != null && !ci.getPhonenum4().equals("") && !ci.getPhonenum4().equals("null")) {
								ci.setLcdh(ci.getPhonenum4());
							} else {
								ci.setLcdh("暂无");
							}
						} else {
							ci.setLcdh("暂无");
						}
						
						list_financial.add(ci);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return list_financial;
	}
	
	public static List<CarInsurance> getInsurance(String json) {
		List<CarInsurance> list_financial = new ArrayList<CarInsurance>();;
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONArray ja_finan = object.optJSONArray("insuranceList");
				if(ja_finan != null && ja_finan.length() > 0) {
					for(int i = 0; i < ja_finan.length(); i++) {
						CarInsurance ci = new CarInsurance();
						JSONObject jo = ja_finan.optJSONObject(i);
						ci.setInsuranceID(jo.optString("id"));
						ci.setInsuranceImgUrl(jo.optString("logoURL"));
						ci.setInsuranceAd(jo.optString("activityInfo"));
						ci.setPhoneName1(jo.optString("phoneName1"));
						ci.setInsuranceTel(jo.optString("phoneNumber1"));
						
						ci.setPhoneName2(jo.optString("phoneName2"));
						ci.setRenewalTel(jo.optString("phoneNumber2"));
						
						ci.setPhoneName3(jo.optString("phoneName3"));
						ci.setPhonenum3(jo.optString("phoneNumber3"));
						
						ci.setPhoneName4(jo.optString("phoneName4"));
						ci.setPhonenum4(jo.optString("phoneNumber4"));
						
						ci.setInsuranceName(jo.optString("hqname"));
						
						List<String> phoneSum = new ArrayList<String>();
						if(ci.getInsuranceTel() != null && !ci.getInsuranceTel().equals("") && !ci.getInsuranceTel().equals("null")) {
							phoneSum.add(ci.getInsuranceTel());
						}
						if(ci.getRenewalTel() != null && !ci.getRenewalTel().equals("") && !ci.getRenewalTel().equals("null")) {
							phoneSum.add(ci.getRenewalTel());
						}
						if(ci.getPhonenum3() != null && !ci.getPhonenum3().equals("") && !ci.getPhonenum3().equals("null")) {
							phoneSum.add(ci.getPhonenum3());
						}
						if(ci.getPhonenum4() != null && !ci.getPhonenum4().equals("") && !ci.getPhonenum4().equals("null")) {
							phoneSum.add(ci.getPhonenum4());
						}
						ci.setPhoneSum(phoneSum);
						
						if(ci.getPhoneName1().equals("报险电话")) {
							if(ci.getInsuranceTel() != null && !ci.getInsuranceTel().equals("") && !ci.getInsuranceTel().equals("null")) {
								ci.setBxdh(ci.getInsuranceTel());
							} else {
								ci.setBxdh("暂无");
							}
						} else if(ci.getPhoneName2().equals("报险电话")) {
							if(ci.getRenewalTel() != null && !ci.getRenewalTel().equals("") && !ci.getRenewalTel().equals("null")) {
								ci.setBxdh(ci.getRenewalTel());
							} else {
								ci.setBxdh("暂无");
							}
						} else if(ci.getPhoneName3().equals("报险电话")) {
							if(ci.getPhonenum3() != null && !ci.getPhonenum3().equals("") && !ci.getPhonenum3().equals("null")) {
								ci.setBxdh(ci.getPhonenum3());
							} else {
								ci.setBxdh("暂无");
							}
						} else if(ci.getPhoneName4().equals("报险电话")) {
							if(ci.getPhonenum4() != null && !ci.getPhonenum4().equals("") && !ci.getPhonenum4().equals("null")) {
								ci.setBxdh(ci.getPhonenum4());
							} else {
								ci.setBxdh("暂无");
							}
						} else {
							ci.setBxdh("暂无");
						}
						
						//
						if(ci.getPhoneName1().equals("续保电话")) {
							if(ci.getInsuranceTel() != null && !ci.getInsuranceTel().equals("") && !ci.getInsuranceTel().equals("null")) {
								ci.setXbdh(ci.getInsuranceTel());
							} else {
								ci.setXbdh("暂无");
							}
						} else if(ci.getPhoneName2().equals("续保电话")) {
							if(ci.getRenewalTel() != null && !ci.getRenewalTel().equals("") && !ci.getRenewalTel().equals("null")) {
								ci.setXbdh(ci.getRenewalTel());
							} else {
								ci.setXbdh("暂无");
							}
						} else if(ci.getPhoneName3().equals("续保电话")) {
							if(ci.getPhonenum3() != null && !ci.getPhonenum3().equals("") && !ci.getPhonenum3().equals("null")) {
								ci.setXbdh(ci.getPhonenum3());
							} else {
								ci.setXbdh("暂无");
							}
						} else if(ci.getPhoneName4().equals("续保电话")) {
							if(ci.getPhonenum4() != null && !ci.getPhonenum4().equals("") && !ci.getPhonenum4().equals("null")) {
								ci.setXbdh(ci.getPhonenum4());
							} else {
								ci.setXbdh("暂无");
							}
						} else {
							ci.setXbdh("暂无");
						}
						
						
						list_financial.add(ci);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return list_financial;
	}
	
	public static NSDTO getNS(String json) {
		NSDTO dto = null;
		try {
			JSONObject object = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONObject jo = object.optJSONObject("inspectionShop");
				
				dto = new NSDTO();
				if(jo != null) {
					dto.setId(jo.optString("id"));
					dto.setShopName(jo.optString("shopName"));
					dto.setShortName(jo.optString("shortName"));
					dto.setShopNumber(jo.optString("shopNumber"));
					dto.setShopAddress(jo.optString("shopAddress"));
					dto.setShopPhone(jo.optString("shopPhone"));
					dto.setLandmark(jo.optString("landmark"));
					dto.setxCoordinates(jo.optString("xCoordinates"));
					dto.setyCoordinates(jo.optString("yCoordinates"));
					dto.setQueueingProbability(jo.optString("queueingProbability"));
					dto.setPicAddr(jo.optString("picAddr"));
					dto.setScore(jo.optString("score"));
					dto.setCityCode(jo.optString("cityCode"));
					dto.setDistance(jo.optString("distance"));
					
					JSONArray ja = jo.optJSONArray("serviceList");
					if(ja != null && ja.length() > 0) {
						List<NSDTO.TC> list_tc = new ArrayList<NSDTO.TC>();
						for(int i = 0; i < ja.length(); i++) {
							JSONObject jo_tc = ja.getJSONObject(i);
							NSDTO.TC tc = new NSDTO.TC();
							tc.setId(jo_tc.optString("id"));
							tc.setCashPrice(jo_tc.optString("serviceName"));
							tc.setCategoryId(jo_tc.optString("categoryId"));
							tc.setFacePrice(jo_tc.optString("facePrice"));
							tc.setServiceName(jo_tc.optString("serviceName"));
							list_tc.add(tc);
						}
						dto.setServiceInfoList(list_tc);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return dto;
	}
	
	public static WearherInfo getWeather(String json) {
		WearherInfo weather = new WearherInfo();
		try {
			JSONObject jo = new JSONObject(json);
			JSONObject jo_weather = jo.optJSONObject("weatherinfo");
			String weather1 = jo_weather.optString("weather1");
			String weather2 = jo_weather.optString("weather2");
			String weather3 = jo_weather.optString("weather3");
			weather.setTq_info(weather1);
			weather.setTq_info_2(weather2);
			weather.setTq_info_3(weather3);
			if(weather1.contains("雨") || weather1.contains("雪") || weather1.contains("沙") || weather1.contains("霾")) {
//				weather.setXc_number("不适宜");
				weather.setXc_number(WearherInfo.bsy);
			} else if(weather2.contains("雨") || weather2.contains("雪") || weather2.contains("沙") || weather2.contains("霾")) {
//				weather.setXc_number("较不适宜");
				weather.setXc_number(WearherInfo.jbsy);
			} else if(weather3.contains("雨") || weather3.contains("雪") || weather3.contains("沙") || weather3.contains("霾")) {
//				weather.setXc_number("较适宜");
				weather.setXc_number(WearherInfo.jsy);
			} else {
//				weather.setXc_number("适宜");
				weather.setXc_number(WearherInfo.sy);
			}
			
			//设置图片
			int position = weather1.lastIndexOf("转");
			if(position != -1) {
				weather1 = weather1.substring(position + 1, weather1.length());
			}
			if(weather1.contains("沙")) {
				weather.setImgRes(R.drawable.wea_li);
			} else if(weather1.contains("霾")) {
				weather.setImgRes(R.drawable.wea_li);
			} else if(weather1.contains("雷")) {
				weather.setImgRes(R.drawable.wea_lei);
			} else if(weather1.contains("雾")) {
				weather.setImgRes(R.drawable.wea_wu);
			} else if(weather1.contains("晴")) {
				weather.setImgRes(R.drawable.wea_qtian);
			} else if(weather1.contains("云")) {
				weather.setImgRes(R.drawable.wea_duoyun);
			} else if(weather1.contains("阴")) {
				weather.setImgRes(R.drawable.wea_yin);
			} else if(weather1.contains("雪")) {
				weather.setImgRes(R.drawable.wea_xue);
			} else if(weather1.contains("雨")) {
				weather.setImgRes(R.drawable.wea_yu);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return weather;
	}
	
	public static Restrictions getRestri(String json) {
		Restrictions restri = null;
		try {
			JSONObject jo = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONObject jo_res = jo.optJSONObject("DRList");
				if(jo_res != null) {
					restri = new Restrictions();
					restri.setdRRegion(jo_res.optString("DRRegion"));
					restri.setdRRule(jo_res.optString("DRRule"));
//					restri.setdRTime(jo_res.optString("DRTime"));
					restri.setdRNumber(jo_res.optString("tailNums"));
				}
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return restri;
	}
	
	
	public static DJDTO getDJ(String json) {
		DJDTO dj = new DJDTO();
		try {
			JSONObject jo = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				JSONObject jo_dj = jo.optJSONObject("designatedDrivingInfo");
				dj.setPhoneNumber(jo_dj.optString("phoneNumber"));
				dj.setUrl(jo_dj.optString("url"));
			}
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
		
		return dj;
	}
	
	public static THDTO getTH(String json) {
		THDTO th = new THDTO();
		try {
			JSONObject jo = new JSONObject(json);
			if(StringUtils.isSuccess(json)) {
				th.setUrl(jo.optString("url"));
			}
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
		return th;	
	}
	
	public static WearherInfo getWeatherInfo(String json) {
		WearherInfo info = null;
		try {
			if(StringUtils.isSuccess(json)) {
				JSONObject jo = new JSONObject(json);
				JSONObject jo_wea = jo.optJSONObject("weatherInfo");
				if(jo_wea != null) {
					
					info = new WearherInfo();
					info.setTemp(jo_wea.optString("temp"));
					info.setTq_info(jo_wea.optString("weather"));
					info.setXc_number(jo_wea.optString("washIndex"));
					info.setCurrentTemp(jo_wea.optString("currentTemp"));
					
					String weather1 = info.getTq_info();
					//设置图片
					int position = weather1.lastIndexOf("转");
					if(position != -1) {
						weather1 = weather1.substring(0, position);
					}
					if(weather1.contains("沙")) {
						info.setImgRes(R.drawable.wea_li);
					} else if(weather1.contains("霾")) {
						info.setImgRes(R.drawable.wea_li);
					} else if(weather1.contains("雷")) {
						info.setImgRes(R.drawable.wea_lei);
					} else if(weather1.contains("雾")) {
						info.setImgRes(R.drawable.wea_wu);
					} else if(weather1.contains("晴")) {
						info.setImgRes(R.drawable.wea_qtian);
					} else if(weather1.contains("云")) {
						info.setImgRes(R.drawable.wea_duoyun);
					} else if(weather1.contains("阴")) {
						info.setImgRes(R.drawable.wea_yin);
					} else if(weather1.contains("雪")) {
						info.setImgRes(R.drawable.wea_xue);
					} else if(weather1.contains("雨")) {
						info.setImgRes(R.drawable.wea_yu);
					}
					
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return info;
	}
}
